#include "wds_game_editor.h"
#include "wds_game.h"
#include "wds_define.h"

#include "editor/editor_brush.h"
#include "application/game_script.h"
#include "math/spline2d.h"
#include "math/facing.h"
#include "math/interpolation.h"
#include "console/console.h"
#include "ui/ui_manager.h"
#include "gameflow/game_flow_manager.h"
#include "dd/dd_man.h"
#include "font/font_manager.h"
#include "script/scripthelper.h"
#include "font/font_manager.h"
#include "input/keyboard.h"
#include "graphics/graphics_util.h"

#include "util/mmgr.h"		    // Needs to come in early
#include "util/common_macros.h"		// macros
#include "util/log.h"		    // logging
#include "util/timer.h"		    // logging


#include <algorithm>
#include <cassert>
using namespace script;


//////////////////////////////////////////////////////////
/// Tile objects
class WDSBrushTile : public EditorBrush
{
public:
	WDSBrushTile(WDSGameEditor* pEditor) :
		EditorBrush(pEditor),
		m_Type(TILE_HARD)
	{		
		m_HelpText = " LMB to Place, \n RMB to delete, \n MWheel To change Type";		
		
	};
	
	virtual void			CreateObj()
	{
		m_Type = TILE_HARD;
	};

	virtual void	Render(const math::Vec2& Offset, float Scale)
	{
		/*if(m_Type > 0 && m_Type < TILE_COUNT)
		{
			if(m_Type == TILE_UNMOVEABLEGEM2)
			{	
				ui::UISprite* pSprite2 = ((WDSGame*)GetGame())->GetTileSprite(TILE_HARD);
				pSprite2->m_Pos = m_pEditor->GetMousePos();
				pSprite2->RenderRotated();
				
			}

			ui::UISprite* pSprite = ((WDSGame*)GetGame())->GetTileSprite(m_Type);
			pSprite->m_Pos = m_pEditor->GetMousePos();
			pSprite->RenderRotated();
			FontManager::Instance().PrintCentered(m_pEditor->GetMousePos(), "%i",  m_Type);
		}*/
	};

	// Rotating is changing type
	virtual void	Rotate(int Dir)
	{
		m_Type =  TILE_TYPE((int)m_Type + 1);
		if ( m_Type >= TILE_COUNT)
			m_Type = TILE_HARD;
	};

	virtual void	PressLMB()
	{
		
	};
	
	virtual bool	TryDelete(const math::Vec2& P) 
	{ 
		
		return false;
	};	

	TILE_TYPE		m_Type;
	
};




WDSGameEditor::WDSGameEditor(GameBase* pGame) : EditorMain(pGame)
{
	SetHelp("Editor Help [H]:						\n" 
			"(1): Place Tiles						\n"			
			"(2): Place Bombs						\n"			
			"(F9): Save								\n"
			"(F10): Load							\n");
}

void		WDSGameEditor::KeyPressed(input::Keyboard::KEY* pKey)
{
	switch (pKey->KeyID)
	{
			
		case KEY_1:
			SetBrush(new WDSBrushTile(this)); 				
		break;		

		case KEY_2:
					
		break;	

		default:
			EditorMain::KeyPressed(pKey);
		break;
	}
}



	